package com.plian.system.controller.sys.file;

import com.plian.Tools.base.BaseController;
import com.plian.Tools.pagedata.PageData;
import com.plian.system.model.ObjResult;
import com.plian.system.service.sys.file.FileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartHttpServletRequest;

import javax.servlet.http.HttpServletResponse;

@RestController
@RequestMapping(value = "api/file")
public class FileController extends BaseController {
    @Autowired
    FileService fileService;
//    @PostMapping(value = "/save")
//    public ObjResult save(@RequestBody PageData pd){
//       return fileService.saveAll(pd);
//    }
//    @PostMapping(value = "/edit")
//    public ObjResult edit(@RequestBody PageData pd){
//       return fileService.edit(pd);
//    }
    @RequestMapping(value = "/upFiles")
//    @PassToken
    public ObjResult upFiles(MultipartHttpServletRequest request){
       return fileService.upFiles(request);
    }
    @RequestMapping(value = "/fileDown")
//    @PassToken
    public void fileDown( HttpServletResponse response) throws Exception {
        PageData pd=this.getPageData();
        fileService.fileDown(pd,response);
    }

    /**
     * 根据主表查询
     * @return
     */
    @RequestMapping(value = "/listParentId")
    public ObjResult listParentId(@RequestBody PageData pd){
        return fileService.listParentId(pd);
    }

    @RequestMapping(value = "/view")
//    @PassToken
    public void view( HttpServletResponse response) throws Exception {
        PageData pd=this.getPageData();
        fileService.view(pd,response);
    }
    @RequestMapping(value = "/topdf")
//    @PassToken
    public ObjResult topdf(@RequestBody PageData pd) throws Exception {
        return fileService.topdf(pd);
    }

    /**
     * 下载excel文件 并删除
     * @param key
     * @param response
     */
    @GetMapping("/excelDownload/{key}")
//    @PassToken
    public ResponseEntity<byte[]> excelDownload(@PathVariable String key, HttpServletResponse response){
        return fileService.excelDownload(key);
    }
}
